/**
 * 扩展 jquery
 */

(function($){

    $.ajaxSetup({
        cache:false, // 禁用缓存
        timeout:60000, // 超时时间，60秒
        error:function(xhr,t,et){
            $.messager.alert("提示","操作失败！","error");
        },
        complete:function(xhr,ts){
            var exception=xhr.getResponseHeader("exception");
            if(exception){
                $.messager.alert("提示","操作异常！","error");
            }
        }
    });

    $.extend({
        loading:function(message){
            var msg=message||"正在加载中，请稍候......";
            var $datagridMaskDiv=$("<div class=\"datagrid-mask\"></div>");
            $datagridMaskDiv.css({display:"block",width:"100%",height:"100%",zIndex:9998}).appendTo($(document.body));
            var $datagridMaskMsg=$("<div class=\"datagrid-mask-msg\"></div>").html(msg).appendTo($(document.body));
            var width=$datagridMaskMsg.width();
            var height=$datagridMaskMsg.height();
            $datagridMaskMsg.css({height:height,lineHeight:"15px",display:"block",cursor:"wait",left:($(window).width()-width)/2,top:"30%",zIndex:9999});
        },
        loaded:function(){
            $(".datagrid-mask").remove();
            $(".datagrid-mask-msg").remove();
        },
        fullScreen:function(){
            if ($.util.supportsFullScreen) {
                if ($.util.isFullScreen()) {
                    $.util.cancelFullScreen();
                } else {
                    $.util.requestFullScreen();
                }
            } else {
                $.messager.alert("提示","当前浏览器不支持全屏 API，请更换至最新的 Chrome/Firefox/Safari 浏览器或通过 F11 快捷键进行操作。","info");
            }
        }
    });

    $.fn.extend({
        loading:function(message){
            var msg=message||"正在加载中，请稍候......";
            var $datagridMaskDiv=$("<div class=\"datagrid-mask\"></div>");
            $datagridMaskDiv.css({display:"block",width:"100%",height:"100%",zIndex:9998}).appendTo($(this));
            var $datagridMaskMsg=$("<div class=\"datagrid-mask-msg\"></div>").html(msg).appendTo($(this));
            var width=$datagridMaskMsg.width();
            var height=$datagridMaskMsg.height();
            $datagridMaskMsg.css({display:"block",left:($(this).width()-width)/2,top:"30%",zIndex:9999});
        },
        loaded:function(){
            $(this).find(".datagrid-mask").remove();
            $(this).find(".datagrid-mask-msg").remove();
        }
    });

})(jQuery);